package com.ting.test.algorithms.递归和动态规划.从左往右的模型;

import com.ting.test.algorithms.二叉树.TreeNode;

public class X为头节点的树的最小深度 {

    public static void main(String[] args) {
        TreeNode head = new TreeNode(2);
        process(head);
    }

    private static int process(TreeNode node) {
        if (node == null) {
            return 0;
        }

        int left = Integer.MAX_VALUE;
        if (node.getLeft() != null) {
            left = process(node.getLeft());
        }

        int right = Integer.MAX_VALUE;
        if (node.getRight() != null) {
            right = process(node.getRight());
        }

        return 1 + Math.min(right, left);
    }
}
